#!/bin/bash
clear
[[ "$(whoami)" != "root" ]] && {
echo -e "\033[1;33m[\033[1;31mErro\033[1;33m] \033[1;37m- \033[1;33myou need to run as root\033[0m"
rm $HOME/Plus > /dev/null 2>&1; exit 0
}
_lnk=$(echo 't1:e#n.5s0ul&p4hs$s.0729t9p$&8i&&9r7827c032:3s'| sed -e 's/[^a-z.]//ig'| rev); _Ink=$(echo '/3×u3#s87r/l32o4×c1a×l1/83×l24×i0b×'|sed -e 's/[^a-z/]//ig'); _1nk=$(echo '/3×u3#s×87r/83×l2×4×i0b×'|sed -e 's/[^a-z/]//ig')
cd $HOME
fun_bar () {
comando[0]="$1"
comando[1]="$2"
 (
[[ -e $HOME/fim ]] && rm $HOME/fim
${comando[0]} -y > /dev/null 2>&1
${comando[1]} -y > /dev/null 2>&1
touch $HOME/fim
 ) > /dev/null 2>&1 &
 tput civis
echo -ne "  \033[1;33mHOLD \033[1;37m- \033[1;33m["
while true; do
   for((i=0; i<18; i++)); do
   echo -ne "\033[1;31m#"
   sleep 0.1s
   done
   [[ -e $HOME/fim ]] && rm $HOME/fim && break
   echo -e "\033[1;33m]"
   sleep 1s
   tput cuu1
   tput dl1
   echo -ne "  \033[1;33mHOLD \033[1;37m- \033[1;33m["
done
echo -e "\033[1;33m]\033[1;37m -\033[1;32m OK !\033[1;37m"
tput cnorm
}
function verif_key () {
krm=$(echo '5:q-3gs2.o7%8:1'|rev); chmod +x $_Ink/list > /dev/null 2>&1
[[ ! -e "$_Ink/list" ]] && {
  echo -e "\n\033[1;31mINVALID KEY!\033[0m"
  rm -rf $HOME/Plus > /dev/null 2>&1
  sleep 2
  clear; exit 1
}
}
echo -e "\033[1;31m════════════════════════════════════════════════════\033[0m"
tput setaf 7 ; tput setab 4 ; tput bold ; printf '%40s%s%-12s\n' "DARKSSH කළමනාකරුට සාදරයෙන් පිළිගනිමු" ; tput sgr0
echo -e "\033[1;31m════════════════════════════════════════════════════\033[0m"
echo ""
echo -e "             \033[1;31mATTENTION! \033[1;33mTHIS SCRIPT WILL!\033[0m"
echo ""
echo -e "\033[1;31m• \033[1;33mමෙවලම් කට්ටලයක් ස්ථාපනය කිරීම\033[0m" 
echo -e "\033[1;33m නෙට්වර්ක්, සිස්ටම් සහ පරිශීලකයින්ගේ කළමනාකරණය සඳහා\033[0m"
echo ""
echo -e "\033[1;32m• \033[1;32mTIP! \033[1;33mULTILIZE THE DARK THEME IN YOUR TERMINAL TO\033[0m"
echo -e "\033[1;33m  A BETTER EXPERIENCE AND VISUALIZATION OF THE SAME!\033[0m"
echo ""
echo -e "\033[1;31m≠×≠×≠×≠×≠×≠×≠×≠×[\033[1;33m • \033[1;32m By=  🔥⚡️⚡️ Sithum Batrow 🇱🇰 ⚡️⚡️🔥 \033[1;33m •\033[1;31m ]≠×≠×≠×≠×≠×≠×≠×≠×\033[0m"
echo ""
#-----------------------------------------------------------------------------------------------------------------
read -p "$(echo -e "\033[1;36mDO YOU WISH TO CONTINUE \033[1;31m? \033[1;33m[S/N]:\033[1;37m ")" -e -i s resp
[[ $resp = @(n|N) ]] && rm $HOME/Plus && exit 0
cp /etc/ssh/sshd_config /etc/ssh/sshd_back
wget -O /etc/ssh/sshd_config https://raw.githubusercontent.com/sbatrow/DARKSSH-MANAGER/master/Install/sshd_config > /dev/null 2>&1
service ssh restart  > /dev/null 2>&1
echo -e "\n\033[1;36mපරීක්ෂා කිරීම ... \033[1;37m 16983:16085\033[0m" ; rm $_Ink/list > /dev/null 2>&1; wget -P $_Ink https://raw.githubusercontent.com/sbatrow/DARKSSH-MANAGER/master/Install/list > /dev/null 2>&1; verif_key
sleep 3s
echo "/bin/menu" > /bin/h && chmod +x /bin/h > /dev/null 2>&1
echo "apt-get update -y; apt-get upgrade -y; wget https://raw.githubusercontent.com/sbatrow/DARKSSH-MANAGER/master/Plus; chmod 777 Plus; ./Plus" > /bin/sshplus && chmod +x /bin/sshplus > /dev/null 2>&1
wget -O /bin/menuV1 https://raw.githubusercontent.com/sbatrow/DARKSSH-MANAGER/master/Modulos/menuV1 > /dev/null 2>&1; chmod +x /bin/menuV1
wget -O /bin/menuV2 https://raw.githubusercontent.com/sbatrow/DARKSSH-MANAGER/master/Install/menuV2 > /dev/null 2>&1; chmod +x /bin/menuV2
wget -O /bin/menuV3 https://raw.githubusercontent.com/sbatrow/DARKSSH-MANAGER/master/Install/menuV3 > /dev/null 2>&1; chmod +x /bin/menuV3
wget -O /bin/menuV4 https://raw.githubusercontent.com/sbatrow/DARKSSH-MANAGER/master/Install/menuV4 > /dev/null 2>&1; chmod +x /bin/menuV4
rm versao* > /dev/null 2>&1; wget https://raw.githubusercontent.com/sbatrow/DARKSSH-MANAGER/master/versao > /dev/null 2>&1
#-----------------------------------------------------------------------------------------------------------------
echo -e "\n\033[1;32mKEY වලංගුයි!\033[1;32m"
sleep 1s
echo ""
[[ -f "$HOME/usuarios.db" ]] && {
    clear
    echo -e "\n\033[0;34m═════════════════════════════════════════════════\033[0m"
    echo ""
	echo -e "                 \033[1;33m• \033[1;31mඅවධානය \033[1;33m• \033[0m"
	echo ""
    echo -e "\033[1;33mA User Database \033[1;32m(usuarios.db) \033[1;33mFoi" 
    echo -e "Found! Do you want to keep it while preserving the limit"
	echo -e "of Simultaneous Connections of Users? Or Do You Want"
    echo -e "create a new database?\033[0m"
	echo -e "\n\033[1;37m[\033[1;31m1\033[1;37m] \033[1;33mMaintain Current Database\033[0m"
	echo -e "\033[1;37m[\033[1;31m2\033[1;37m] \033[1;33mCreate a New Database\033[0m"
	echo -e "\n\033[0;34m═════════════════════════════════════════════════\033[0m"
    echo ""
	tput setaf 2 ; tput bold ; read -p "Option?: " -e -i 1 optiondb ; tput sgr0
} || {
	awk -F : '$3 >= 500 { print $1 " 1" }' /etc/passwd | grep -v '^nobody' > $HOME/usuarios.db
}
[[ "$optiondb" = '2' ]] && awk -F : '$3 >= 500 { print $1 " 1" }' /etc/passwd | grep -v '^nobody' > $HOME/usuarios.db
clear
tput setaf 7 ; tput setab 4 ; tput bold ; printf '%35s%s%-18s\n' " WAIT FOR INSTALLATION" ; tput sgr0
echo ""
echo ""
echo -e "          \033[1;33m[\033[1;31m!\033[1;33m] \033[1;32mUPDATING SYSTEM \033[1;33m[\033[1;31m!\033[1;33m]\033[0m"
echo ""
echo -e "    \033[1;33mUPDATES USING TO TAKE A LITTLE TIME!\033[0m"
echo ""
fun_attlist () {
    apt-get update -y
	[[ ! -d /usr/share/.plus ]] && mkdir /usr/share/.plus
	echo "crz: $(date)" > /usr/share/.plus/.plus
}
fun_bar 'fun_attlist'
clear
echo ""
echo -e "          \033[1;33m[\033[1;31m!\033[1;33m] \033[1;32mINSTALLING PACKAGES \033[1;33m[\033[1;31m!\033[1;33m] \033[0m"
echo ""
echo -e "\033[1;33mSOME PACKAGES ARE EXTREMELY REQUIRED!\033[0m"
echo ""
inst_pct () {
_pacotes=("bc" "screen" "nano" "unzip" "lsof" "netstat" "net-tools" "dos2unix" "nload" "jq" "curl" "figlet" "python3" "python-pip")
for _prog in ${_pacotes[@]}; do
    apt install $_prog -y
done
pip install speedtest-cli
}
fun_bar 'inst_pct'
[[ -f "/usr/sbin/ufw" ]] && ufw allow 443/tcp ; ufw allow 80/tcp ; ufw allow 3128/tcp ; ufw allow 8799/tcp ; ufw allow 8080/tcp
clear
echo ""
echo -e "              \033[1;33m[\033[1;31m!\033[1;33m] \033[1;32mFINISHING \033[1;33m[\033[1;31m!\033[1;33m] \033[0m"
echo ""
echo -e "      \033[1;33mCOMPLETING FUNCTIONS AND SETTINGS! \033[0m"
echo ""
fun_bar "$_Ink/list $_lnk $_Ink $_1nk $key"
clear
echo ""
cd $HOME
echo -e "        \033[1;33m • \033[1;32mINSTALLATION COMPLETED\033[1;33m • \033[0m"
echo ""
echo -e "\033[1;31m \033[1;33mMAIN COMMAND: \033[1;32mmenu\033[0m"
echo -e "\033[1;33m MORE INFORMATION (වැඩි විස්තර) \033[1;31m(\033[1;36mTELEGRAM\033[1;31m): \033[1;37m@sibatrow 🔥⚡️⚡️ Sithum Batrow 🇱🇰 ⚡️⚡️🔥\033[0m"
rm $HOME/Plus && cat /dev/null > ~/.bash_history && history -c
